import 'package:epidemic_data/config/styles.dart';
import 'package:flutter/material.dart';
import 'package:fl_chart/fl_chart.dart';

class CovidBarChart extends StatelessWidget {
  final List<double> covidCases;

  const CovidBarChart({required this.covidCases});

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 350.0,
      decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(20.0),
            topRight: Radius.circular(20.0),
          )),
      child: Column(
        children: <Widget>[
          Container(
            padding: const EdgeInsets.all(20.0),
            alignment: Alignment.centerLeft,
            child: Text(
              'Daily New Cases',
              style: const TextStyle(
                fontSize: 22.0,
                fontWeight: FontWeight.bold,
              ),
            ),
          ),
          Container(
            width: MediaQuery.of(context).size.width * 0.85,
            child: BarChart(BarChartData(
              alignment: BarChartAlignment.spaceAround,
              barTouchData: BarTouchData(enabled: false),
              maxY: 16.0,
              titlesData: FlTitlesData(
                  show: true,
                  bottomTitles: SideTitles(
                      margin: 10.0,
                      showTitles: true,
                      rotateAngle: 35.0,
                      getTitles: (double value) {
                        switch (value.toInt()) {
                          case 0:
                            return 'May 24';
                          case 1:
                            return 'May 25';
                          case 2:
                            return 'May 26';
                          case 3:
                            return 'May 27';
                          case 4:
                            return 'May 28';
                          case 5:
                            return 'May 29';
                          case 6:
                            return 'May 30';
                          default:
                            return '';
                        }
                      }),
                leftTitles: SideTitles(
                  margin: 10.0,
                  showTitles: true,
                  getTitles: (value) {
                    if (value == 0) {
                      return '0';
                    }
                    return ' ';
                  }
                )
              ),
              barGroups: covidCases
                  .asMap()
                  .map((key, value) => MapEntry(
                      key,
                      BarChartGroupData(
                        x: key,
                        barRods: [
                          BarChartRodData(
                            y: value,
                            colors: [Colors.red],
                          ),
                        ],
                      )))
                  .values
                  .toList(),
            )),
          )
        ],
      ),
    );
  }
}
